﻿using System;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json.Linq;

namespace PlurkApi
{
    public class channel
    {
        #region Properties

        /// <summary>
        /// comet_server, for example : http://comet03.plurk.com/comet/1235515351741/?channel=generic-4-f733d8522327edf87b4d1651e6395a6cca0807a0"
        /// </summary>
        public string comet_server { get; set; }

        /// <summary>
        /// channel_name, for example  :  generic-4-f733d8522327edf87b4d1651e6395a6cca0807a0
        /// </summary>
        public string channel_name { get; set; }

        /// <summary>
        /// Gets or sets the offset.
        /// </summary>
        public int? offset { get; private set; }

        #endregion

        /// <summary>
        /// Initializes a new instance of the <see cref="channel"/> class.
        /// </summary>
        public channel(){}

        /// <summary>
        /// Initializes a new instance of the <see cref="channel"/> class.
        /// </summary>
        /// <param name="jsonString">The json string.</param>
        public channel(string jsonString)
        {
            var obj = JObject.Parse(jsonString);
            if (obj.Count <= 0) { return; }

            comet_server = (obj["comet_server"] == null) ? string.Empty : (string)obj["comet_server"];
            channel_name = (obj["channel_name"] == null) ? string.Empty : (string)obj["channel_name"];
        }

        /// <summary>
        /// Sets the offset.
        /// </summary>
        /// <param name="offset">The offset.</param>
        public void setOffset(int? offset)
        {
            offset = offset;
        }
    }
}
